/*
 * TDownloader.h
 *
 *  Created on: 2012-11-5
 *      Author: minhua
 */

#ifndef TDOWNLOADER_H_
#define TDOWNLOADER_H_

#include "../model/TSession.h"
#include <QHash>
#include <QVariant>
#include <QDomElement>
#include <QNetworkReply>
#include <QTimer>

class TDownloader : public QObject
{
	Q_OBJECT

// Member
private:
	TSessionPointer _session;

// Method
public:
	TDownloader(TSessionPointer session, QObject *parent = 0);
	virtual ~TDownloader();
	void download(QString path, QString filename, int msec = 60000);
	void download(QString path, QHash<QString, QVariant> variables, QString filename, int msec = 60000);
	QString getDownloadFilename();

// Signal
signals:
	void finished(bool error);
	void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
	void uploadProgress(qint64 bytesSent, qint64 bytesTotal);


// Slot
private slots:
	void done(QNetworkReply *reply);
	void timeout();

private:
	QTimer         *_timer;
	QString        _path;
	QString        _content;
	QNetworkReply *_reply;
	QString		   _downloadFilename;
};

#endif /* TDOWNLOADER_H_ */
